<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class TestController extends Controller
{
    //
    public function test1(Request $request){
//        print($request->get('s'));
//        $html = file_get_contents("https://www.google.com.sg/search?q=q");
        $method ='GET';
        $reqs = [];
        foreach ($request->all() as $key=>$item ){
            $reqs[$key] = $item;
        }
        $data = http_build_query($reqs);
        $opt=[
            'http' =>[
                'method' => $method,
                'content' => $data,
            ]
        ];
        $cxContext = stream_context_create($opt);

        $html = file_get_contents("https://www.baidu.com/", false, $cxContext);

        return $html;
    }

    private function get($url,$reqs=[]){
        $method ='GET';
        $data = http_build_query($reqs);
//        dd($data);
        $opt=[
            'http' =>[
                'method' => $method,
                'content' => $data,
            ]
        ];
        $cxContext = stream_context_create($opt);
        return file_get_contents($url, false, $cxContext);
    }
    public function wxShare(Request $request){
        $token = $this ->get('https://open.weixin.qq.com/connect/oauth2/authorize',[
            'appid'=> 'wxd65029d719df4252',
            'redirect_uri'=> '',
            'response_type' => 'code',
            'scope' => 'SCOPE',
            'state' => 'STATE#wechat_redirect'
        ]);
        return $token;
    }
}
